package com.wantup.springboot.boot;

import com.wantup.springboot.boot.servlet_file_listener.PersonFilter;
import com.wantup.springboot.boot.servlet_file_listener.PersonServlet;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
  * @author:  zhaoluowei
  * @date :   2018/11/7 10:21
  * @version  1.0
  */
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                            O\ = /O
//                        ____/`---'\____
//                      .   ' \\| |// `.
//                       / \\||| : |||// \
//                     / _||||| -:- |||||- \
//                       | | \\\ - /// | |
//                     | \_| ''\---/'' | |
//                      \ .-\__ `-` ___/-. /
//                   ___`. .' /--.--\ `. . __
//                ."" '< `.___\_<|>_/___.' >'"".
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |
//                 \ \ `-. \_ __\ /__ _/ .-` / /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//
//         .............................................
//                  佛祖保佑             永无BUG
//
//

@SpringBootApplication
@MapperScan("com.wantup.springboot.boot.mapper")
@EnableScheduling
@EnableAsync
public class BootApplication {
    /**
     * SpringBoot默认内置的是jackson。
     *
     *
     * springboot 启动类
     * @param args
     */
    public static void main(String[] args) {
        SpringApplication.run(BootApplication.class, args);
    }

    //可以配置三大过滤器 servlet filter listener

    /**
     * 注册servlet
     *      第一个参数是  servlet对象
     *      第二个参数是  定义的servlet的路径
     *
     * @return
     */
    @Bean
    public ServletRegistrationBean getPersonServlet(){
        ServletRegistrationBean<PersonServlet> registrationBean =
                new ServletRegistrationBean<PersonServlet>(new PersonServlet(),"/personServlet");
        return registrationBean;
    }

    @Bean
    public FilterRegistrationBean getPersonFilter(){
        FilterRegistrationBean<PersonFilter> filterRegistrationBean = new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(new PersonFilter());
        //添加 过滤 访问 路径
        List<String> list = new ArrayList<>();
        list.add("/*");
        filterRegistrationBean.setUrlPatterns(list);


        return filterRegistrationBean;

    }




}
